package com.ghxxzx.dagl.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ghxxzx.dagl.entity.Dajy;
import com.ghxxzx.dagl.mapper.DajyMapper;
import com.ghxxzx.dagl.vo.DajyQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: 刘华
 * @Date: 2020/12/7 17:18
 * @Version 1.0
 */
@EnableScheduling
@Component
public class Tining {
    @Autowired
    private DajyMapper dajyMapper;

    @PostConstruct
    private void initOut(){
        QueryWrapper<Dajy> wrapper = new QueryWrapper<>();
        wrapper.eq("zt", "1");
        List<Dajy> list = dajyMapper.selectList(wrapper);
        for (Dajy dajy : list) {
            jyzt(dajy);
        }
    }
    @Scheduled(cron = "0 55 23 * * *")
    public void borrowOut(){
        QueryWrapper<Dajy> wrapper = new QueryWrapper<>();
        wrapper.eq("zt", "1");
        List<Dajy> list = dajyMapper.selectList(wrapper);
        for (Dajy dajy : list) {
            jyzt(dajy);
        }
    }
    public void jyzt(Dajy record) {
        if (record.getDqsj() != null) {
            Boolean sfgq = sfgq(record.getDqsj(), new Date());
            if (!sfgq) {
                if (Integer.parseInt(record.getZt()) != 3) {
                    record.setZt(3 + "");
                    dajyMapper.updateById(record);
                }
            }
        }

    }
    public Boolean sfgq(Date dqsj, Date newDate) {
        long dqsjTime = dqsj.getTime();
        long time = newDate.getTime();
        if (dqsjTime >= time) {
            return true;
        } else {
            return false;
        }
    }
}
